<?php
/**
 * Elgg owner block
 * Displays page ownership information
 *
 * @package Elgg
 * @subpackage Core
 *
 */

global $CONFIG;

$contents = "";



// Is there a page owner?


if(isloggedin()){
	$owner = page_owner_entity();
	
	
	if ($owner instanceof ElggEntity) {
		$icon = elgg_view("profile/icon",array('entity' => $owner, 'size' => 'medium'));
		if ($owner instanceof ElggUser || $owner instanceof ElggGroup) {
			$info = '<a href="' . $owner->getURL() . '">' . $owner->name . '</a>';
		}
		$display = "<div id=\"owner_block_icon\">" . $icon . "</div>";
		$display .= "<div id=\"owner_block_content\">" . $info . "</div><div class=\"clearfloat ownerblockline\"></div>";

		if ($owner->briefdescription) {
			$desc = $owner->briefdescription;
			$display .= "<div id=\"owner_block_desc\">" . $desc . "</div>";
		}

        
				        
		$contents .= $display;

		/*if($CONFIG->pluginname == "socialcommerce"){
			
			$path = $CONFIG->wwwroot."pg/{$CONFIG->pluginname}/" . $owner->name;
			$ownshop = "<div id=\"owner_block\"><a href=$path>".$owner->name."'s shop</a></div>";
			$contents .= $ownshop;
		}*/
		
	}
	

	// Are there feeds to display?
	/*
	global $autofeed;

	if (isset($autofeed) && $autofeed == true) {
		$url = $url2 = full_url();
		if (substr_count($url,'?')) {
			$url .= "&view=rss";
		} else {
			$url .= "?view=rss";
		}
		$label = elgg_echo('feed:rss');
		$contents .= <<<END

	<div id="owner_block_rss_feed"><a href="{$url}" rel="nofollow">{$label}</a></div>
END;
	}
	
	*/


	// Have we been asked to inject any content? If so, display i
if (isset($vars['content']))
	
	$test = $vars['content'];
		$contents .= $vars['content'];


	$context = get_context();

	if ($context == 'socialcommerce' || $context == 'stores' || $context == 'anything' ) {
		//$contents .= elgg_view('socialcommerce/cat_menu', "asdasd");
		}


	// Add separator in the extended owner_block and owner_block AB	
	//    $contents .= "<div id=\"owner_block_menu_separator\"></div>";
	// Initialise the submenu (plugins can add to the submenu)
	$submenu = get_submenu(); 
	if (!empty($submenu)) {
		$contents .= "<div id=\"owner_block_submenu\">" . $submenu . "</div>"; } 


	if (!empty($contents)) {
		echo "<div id=\"owner_block\">";
		echo $contents;
		echo "</div><div id=\"owner_block_bottom\"></div>";
	}
}
else {
	
	
		$owner = page_owner_entity();

	
	if ($owner instanceof ElggEntity) {
		$icon = elgg_view("profile/icon",array('entity' => $owner, 'size' => 'medium'));
		if ($owner instanceof ElggUser || $owner instanceof ElggGroup) {
			$info = '<a href="' . $owner->getURL() . '">' . $owner->name . '</a>';
		}
		$display = "<div id=\"owner_block_icon\">" . $icon . "</div>";
		$display .= "<div id=\"owner_block_content\">" . $info . "</div><div class=\"clearfloat ownerblockline\"></div>";

		if ($owner->briefdescription) {
			$desc = $owner->briefdescription;
			$display .= "<div id=\"owner_block_desc\">" . $desc . "</div>";
		}

		$contents .= $display;
	}
		
		$submenu = get_submenu(); 
	if (!empty($submenu))
		$contents .= "<div id=\"owner_block_submenu\">" . $submenu . "</div>"; 
	
	//$context = get_context();
	
//	if ($context == 'socialcommerce' || $context == 'stores' || $context == 'anything' ) {
		//$contents .= elgg_view('socialcommerce/cat_menu', "asdasd");
	//}
	//$contents .= elgg_view('socialcommerce/cat_menu', "asdasd");
	
  	$contents .= $vars['content'];	
	if (!empty($contents)) {
		echo "<div id=\"owner_block\">";
		echo $contents;
		echo "</div><div id=\"owner_block_bottom\"></div>";
	}
	
	}
		





